
#ifndef WAVEFILE_H
#define WAVEFILE_H

#include <stdint.h>

/* Audio file information structure */
typedef enum
    {
    LittleEndian,
    BigEndian
    } Endianness;

typedef struct
    {
    uint32_t  RIFFchunksize;
    uint16_t  FormatTag;
    uint16_t  NumChannels;
    uint32_t  SampleRate;
    uint32_t  ByteRate;
    uint16_t  BlockAlign;
    uint16_t  BitsPerSample;
    uint32_t  DataSize;
    } WAVE_FormatTypeDef;

/* Error Identification structure */
typedef enum
    {
    Valid_WAVE_File = 0,
    Invalid_RIFF_ID,
    Invalid_WAVE_Format,
    Invalid_FormatChunk_ID,
    Unsupporetd_FormatTag,
    Unsupporetd_Number_Of_Channel,
    Unsupporetd_Sample_Rate,
    Unsupporetd_Bits_Per_Sample,
    Invalid_DataChunk_ID,
    Unsupporetd_ExtraFormatBytes,
    Invalid_FactChunk_ID
    } ErrorCode;

#define  HEADER_SIZE         44
#define  ChunkID             0x52494646  /* correspond to the letters 'RIFF' */
#define  FileFormat          0x57415645  /* correspond to the letters 'WAVE' */
#define  FormatID            0x666D7420  /* correspond to the letters 'fmt ' */
#define  DataID              0x64617461  /* correspond to the letters 'data' */
#define  FactID              0x66616374  /* correspond to the letters 'fact' */

#define  WAVE_FORMAT_PCM     0x01
#define  FormatChunkSize     0x10
#define  Channel_MONO        0x01
#define  Channel_STEREO      0x02

#define  SampleRate_8000     8000
#define  SampleRate_16000    16000
#define  SampleRate_22050    22050
#define  SampleRate_44100    44100
#define  SampleRate_48000    48000
#define  Bits_Per_Sample_8   8
#define  Bits_Per_Sample_16  16

extern WAVE_FormatTypeDef  WAVE_Format;

ErrorCode WavFile_CODEC_Parsing(uint8_t* HeaderTab);
static uint32_t ReadUnit(u8 NbrOfBytes, Endianness BytesFormat);

#endif